require("./../../js/jquery-nestable2/jquery.nestable.min.js");
import "./../../js/jquery-nestable2/jquery.nestable.min.css";
import { requestPost } from "./../../js/base/utils";

import $ from 'jquery';
global.$ = global.jQuery = $;

(function ($) {
    $('#tree').nestable({ scroll: true });
    $('.dd').nestable('collapseAll');

    $('.tree-tools').on('click', function (e) {
        var action = $(this).data('action');
        if (action === 'expand') {
            $('.dd').nestable('expandAll');
        }
        if (action === 'collapse') {
            $('.dd').nestable('collapseAll');
        }
        $('.tree-tools').removeClass("active");
        $(this).addClass("active");
    });

    $("#sortSave").click(function () {
        var serialize = $('#tree').nestable('serialize');
        requestPost(admin_api_cms_news_category_updateSort, serialize);
    });
})(jQuery);
